import numpy as np
import random as rd
import drawNet as dn
def ER1(n, m):#固定边数ER随机图
    G = np.empty((n, n))
    lst = []
    for i in range(0, n):
        for j in range(i + 1, n):
            G[i][j] = G[j][i] = -1
            lst.append([i, j])
            lst.append([j, i])
    tmp_m = m
    while(tmp_m > 0):
        k = rd.choice(lst)
        G[k[0]][k[1]] = 1
        G[k[1]][k[0]] = 1
        lst.remove(k)
        lst.remove([k[1], k[0]])
        tmp_m -= 1
    return G

def ER2(n, p):#固定连边概率ER随机图
    G = np.empty((n, n))
    for i in range(0, n):
        G[i][i] = -1
        for j in range(i + 1, n):
            G[i][j] = G[j][i] = -1
            r = rd.random()
            if(r < p):
                G[i][j] = G[j][i] = 1
    return G

dn.drawGraph(ER1(30, 100))
dn.drawGraph(ER2(10, 1.0 / 6.0))